/**
 * Created by Administrator on 2017/3/21.
 */

var express = require('express');
var router = express.Router();
var events = require("events");
var NoteDao = require("../my_modules/NoteDao");

/**
 * 查询一条数据
 */
router.get('/', function(req, res) {
    tid  = req.query.tid;
    var emitter = new events.EventEmitter();
    emitter.on("selectOneNoteSuccess" ,function (result) {
        if(result.length>0){
            res.send(result[0]);
        }else{
            obj = {
                msg:"没有查询到该纸条，可能已经被管理员删除！",
            }
            res.send(obj);
        }
        res.end();
    });
    emitter.on("selectOneNoteError",function (error) {
        console.log(error);
        obj = {
            msg:"查询数据出错！",
        }
        res.send(obj);
        res.end();
    });
    var noteDao = new NoteDao();
    noteDao.selectById(tid,retOne);
    function retOne(emitLabel,result) {
        emitter.emit(emitLabel,result);
    }
});

module.exports = router;
